<template>
  <div v-show="visible" class="panel-wrapper">
    <div class="panel-container">
      <div class="left-panel">
        <div class="panel-header">
          <div class="header-left">
            <h2>{{ title }}</h2>
          </div>
          <div class="header-right">
            <span class="close-btn" @click="closePanel">×</span>
          </div>
        </div>
        <div class="left-panel-content">
          <slot></slot>
        </div>
      </div>
      <div class="right-panel">
        <div class="panel-buttons-wrapper">
          <div class="panel-buttons">
            <button v-for="(layer, index) in panelLayers" :key="layer.id" class="switch-btn"
              :class="{ active: index === currentLayerIndex }" @click="switchPanel(index)">
              {{ layer.name || 'Layer ' + (index + 1) }}
            </button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'RightPanel',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '面板标题'
    },
    panelLayers: {
      type: Array,
      default: () => []
    },
    activeLayerId: {
      type: String,
      default: ''
    }
  },
  computed: {
    currentLayerIndex() {
      return this.panelLayers.findIndex(layer => layer.id === this.activeLayerId);
    }
  },
  methods: {
    closePanel() {
      this.$emit('close');
    },
    switchPanel(index) {
      this.$emit('switch-layer', this.panelLayers[index]);
    }
  }
};
</script>


<style scoped lang="scss">
.panel-wrapper {
  position: fixed;
  top: 110px;
  right: 5px;
  min-width: 300px;
  width: fit-content;
  height: 90vh;
  z-index: 1000;
  display: flex;
  justify-content: flex-end;

  .panel-container {
    display: flex;
    height: 100%;
    position: relative;

    .left-panel {
      min-width: 300px;
      width: fit-content;
      max-width: 600px;
      height: 100%;
      background-color: #ffffff;
      box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
      display: flex;
      flex-direction: column;
      position: relative;
      z-index: 1;

      .panel-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 20px;
        height: 50px;
        border-bottom: 1px solid #e8e8e8;
        background-color: #fafafa;

        .header-left {
          h3 {
            margin: 0;
            font-size: 16px;
            font-weight: 600;
            color: #333;
          }
        }

        .header-right {
          .close-btn {
            font-size: 24px;
            color: #999;
            cursor: pointer;
            transition: color 0.3s;

            &:hover {
              color: #666;
            }
          }
        }
      }

      .left-panel-content {
        flex: 1;
        overflow-y: auto;
        padding: 5px;
        width: fit-content;
        
        // 美化滚动条样式
        &::-webkit-scrollbar {
          width: 6px;
        }

        &::-webkit-scrollbar-track {
          background: #f1f1f1;
          border-radius: 3px;
        }

        &::-webkit-scrollbar-thumb {
          background: #c1c1c1;
          border-radius: 3px;
          transition: background 0.3s ease;
        }

        &::-webkit-scrollbar-thumb:hover {
          background: #a8a8a8;
        }
      }
    }

    .right-panel {
      width: 50px;
      position: absolute;
      left: 0;
      top: 10%;
      height: 80%;
      transform: translateX(-100%);
      z-index: 2;

      .panel-buttons-wrapper {
        height: 100%;
        overflow-y: auto;
        position: relative;
        
        // 美化滚动条样式
        &::-webkit-scrollbar {
          width: 4px;
        }

        &::-webkit-scrollbar-track {
          background: transparent;
        }

        &::-webkit-scrollbar-thumb {
          background: rgba(0, 0, 0, 0.2);
          border-radius: 2px;
          transition: background 0.3s ease;
        }

        &::-webkit-scrollbar-thumb:hover {
          background: rgba(0, 0, 0, 0.4);
        }

        .panel-buttons {
          position: absolute;
          right: 0;
          top: 0;
          transform: translateY(0);
          display: flex;
          flex-direction: column;
          gap: 10px;
          padding: 5px 5px;
          z-index: 3;
    
          .switch-btn {
            padding: 15px 0;
            background-color: #f0f0f0;
            border: none;
            border-radius: 4px 0 0 4px;
            cursor: pointer;
            font-size: 14px;
            color: #666;
            transition: all 0.3s;
            white-space: nowrap;
            writing-mode: vertical-lr;
            text-orientation: mixed;
            height: auto;
            min-height: 80px;
            min-width: 40px;

            &:hover {
              background-color: #e0e0e0;
            }

            &.active {
              background-color: #1890ff;
              color: white;
            }
          }
        }
      }
    }
  }
}

/* 响应式设计 */
@media (max-width: 992px) {
  .left-panel {
    min-width: 250px;
    max-width: 500px;
  }
  
  .right-panel {
    width: 25px;
  }
}

@media (max-width: 768px) {
  .left-panel {
    min-width: 200px;
    max-width: 400px;
  }

  .switch-btn {
    padding: 12px 15px;
    font-size: 12px;
    min-height: 70px;
    min-width: 35px;
  }
  
  .right-panel {
    width: 22px;
  }
}

@media (max-width: 576px) {
  .left-panel {
    min-width: 150px;
    max-width: 300px;
  }

  .switch-btn {
    padding: 10px 12px;
    font-size: 11px;
    min-height: 60px;
    min-width: 30px;
  }
  
  .right-panel {
    width: 20px;
  }
}

// 添加 Firefox 兼容性支持
.panel-wrapper {
  .left-panel-content {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
  }
  
  .panel-buttons-wrapper {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
  }
}
</style>
<!-- <style scoped lang="scss">
.panel-wrapper {
  position: fixed;
  top: 110px;
  right: 5px;
  min-width: 300px;
  width: fit-content;
  height: 90vh;
  z-index: 2000;
  display: flex;
  justify-content: flex-end;

  .panel-container {
    display: flex;
    height: 100%;
    position: relative;

    .left-panel {
      min-width: 300px;
      width: fit-content;
      max-width: 600px;
      height: 100%;
      background-color: #ffffff;
      box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
      display: flex;
      flex-direction: column;
      position: relative;
      z-index: 1;

      .panel-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 20px;
        height: 50px;
        border-bottom: 1px solid #e8e8e8;
        background-color: #fafafa;

        .header-left {
          h3 {
            margin: 0;
            font-size: 16px;
            font-weight: 600;
            color: #333;
          }
        }

        .header-right {
          .close-btn {
            font-size: 24px;
            color: #999;
            cursor: pointer;
            transition: color 0.3s;

            &:hover {
              color: #666;
            }
          }
        }
      }

      .left-panel-content {
        flex: 1;
        overflow-y: auto;
        padding: 5px;
        width: fit-content;
      }
    }

    .right-panel {
      width: 50px;
      position: absolute;
      left: 0;
      top: 10%;
      height: 80%;
      transform: translateX(-100%);
      z-index: 2;

      .panel-buttons-wrapper {
        height: 100%;
        overflow-y: auto;
        position: relative;

        .panel-buttons {
          position: absolute;
          right: 0;
          top: 0;
          transform: translateY(0);
          display: flex;
          flex-direction: column;
          gap: 10px;
          padding: 5px 5px;
          z-index: 3;
    
          .switch-btn {
            padding: 15px 0;
            background-color: #f0f0f0;
            border: none;
            border-radius: 4px 0 0 4px;
            cursor: pointer;
            font-size: 14px;
            color: #666;
            transition: all 0.3s;
            white-space: nowrap;
            writing-mode: vertical-lr;
            text-orientation: mixed;
            height: auto;
            min-height: 80px;
            min-width: 40px;

            &:hover {
              background-color: #e0e0e0;
            }

            &.active {
              background-color: #1890ff;
              color: white;
            }
          }
        }
      }
    }
  }
}

/* 响应式设计 */
@media (max-width: 992px) {
  .left-panel {
    min-width: 250px;
    max-width: 500px;
  }
  
  .right-panel {
    width: 25px;
  }
}

@media (max-width: 768px) {
  .left-panel {
    min-width: 200px;
    max-width: 400px;
  }

  .switch-btn {
    padding: 12px 15px;
    font-size: 12px;
    min-height: 70px;
    min-width: 35px;
  }
  
  .right-panel {
    width: 22px;
  }
}

@media (max-width: 576px) {
  .left-panel {
    min-width: 150px;
    max-width: 300px;
  }

  .switch-btn {
    padding: 10px 12px;
    font-size: 11px;
    min-height: 60px;
    min-width: 30px;
  }
  
  .right-panel {
    width: 20px;
  }
}
</style> -->